﻿using System;
using GeoAPI.Geometries;

namespace YJKGridTopologyCal.Geometries.Implementation
{
	[Serializable]
	public sealed class CoordinateArraySequenceFactory : ICoordinateSequenceFactory
	{
		private CoordinateArraySequenceFactory()
		{
		}

		public static CoordinateArraySequenceFactory Instance
		{
			get
			{
				return CoordinateArraySequenceFactory.instance;
			}
		}

		public ICoordinateSequence Create(Coordinate[] coordinates)
		{
			return new CoordinateArraySequence(coordinates);
		}

		public ICoordinateSequence Create(ICoordinateSequence coordSeq)
		{
			return new CoordinateArraySequence(coordSeq);
		}

		public ICoordinateSequence Create(int size, int dimension)
		{
			if (dimension > 3)
			{
				dimension = 3;
			}
			if (dimension < 2)
			{
				return new CoordinateArraySequence(size);
			}
			return new CoordinateArraySequence(size, dimension);
		}

		public ICoordinateSequence Create(int size, Ordinates ordinates)
		{
			return new CoordinateArraySequence(size, OrdinatesUtility.OrdinatesToDimension(ordinates));
		}

		public Ordinates Ordinates
		{
			get
			{
				return Ordinates.XYZ;
			}
		}

		private static readonly CoordinateArraySequenceFactory instance = new CoordinateArraySequenceFactory();
	}
}
